package poiSeleniumTests;



import org.junit.Before;
import org.junit.Test;
import poi.POIDatabase;
import poi.GeoInfo;
import java.util.Iterator;
import java.util.LinkedList;
import com.thoughtworks.selenium.SeleneseTestCase;


public class GeoServletSeleniumTest  extends SeleneseTestCase {

	@Before
	public void setUp() throws Exception {
		setUp("http://localhost:8080/POISystem/", "*chrome");
	}

	@Test
	public void testGeoServlet()  {
		selenium.open("/POISystem/");
		selenium.click("link=Data from CSV file");
		selenium.waitForPageToLoad("30000");
		assertEquals(false, selenium.isTextPresent("Error reading from CSV file!"));
		assertTrue(selenium.getBodyText().split("<br>").length>0);
		assertEquals(0, (selenium.getBodyText().replaceAll("\n", ",").split(",").length)%5);	
        String baseContent = new String();
        baseContent = "";
        POIDatabase db = new POIDatabase();
        db.connectSource(null);
        LinkedList<GeoInfo> li = db.buildList(null);
        Iterator<GeoInfo> it = li.iterator();
        while (it.hasNext())
        {
        	GeoInfo val = it.next();
        	baseContent += val.toString();
        	if(it.hasNext()) baseContent += "\n";
        }
        assertEquals(selenium.getBodyText(), baseContent);
	}

}
